#include "reportdocumentmainwindow.h"
#include "ui_reportdocumentmainwindow.h"
#include "htmltable.h"
#include <QtPrintSupport/QPrinter>
#include <QFileDialog>

ReportDocumentMainWindow::ReportDocumentMainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ReportDocumentMainWindow)
{
    ui->setupUi(this);

    QString html;
    QFile file("D:\\html.txt");
    file.open(QIODevice::ReadOnly);
    QTextStream in(&file);
    html = in.readAll();
    ui->textBrowser->setHtml(html);

}

ReportDocumentMainWindow::~ReportDocumentMainWindow()
{
    delete ui;
}

void ReportDocumentMainWindow::on_exp_action_E_triggered()
{

    QString fileName = QFileDialog::getSaveFileName(this,"Export PDF",QString(),"*.pdf");
    if(!fileName.isEmpty())
    {
      if(QFileInfo(fileName).suffix().isEmpty())
      {
          fileName.append(".pdf");
       }
       QPrinter  printer(QPrinter::HighResolution);
       printer.setOutputFormat(QPrinter::PdfFormat);
       printer.setPaperSize(QPrinter::A4);
       printer.setOutputFileName(fileName);
       ui->textBrowser->document()->print(&printer);
    }

}

void ReportDocumentMainWindow::on_action_triggered()
{
    w = new MainWindow(this);
    w->show();
}
